unit dmda_Department;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dmModule, FR_DSet, FR_DBSet, DB, ComCtrls, ADODB;

type
  Tdtmda_Department = class(TdtmModule)
    adsMasterDeptID: TStringField;
    adsMasterDeptcode: TStringField;
    adsMasterDeptName: TStringField;
    adsMasterManager: TStringField;
    adsMasterTel: TStringField;
    adsMasterAddress: TStringField;
    adsMasterWriter: TStringField;
    adsMasterWriteTime: TDateTimeField;
    adsMasterModifier: TStringField;
    adsMasterModifyTime: TDateTimeField;
    adsMasterRemark: TStringField;
    adsMasterDeptFullName: TStringField;
    adsMasterDeptType: TWordField;
    adsMasterFax: TStringField;
    adsMasterEmail: TStringField;
    adsMasterHasCheck: TBooleanField;
    adsMasterChecker: TStringField;
    adsMasterCheckTime: TDateTimeField;
    adsMasterSign: TStringField;
    adsMasterFlag: TWordField;
    adsMasterHelperCode: TStringField;
    adsMasterDeptEngName: TStringField;
    adsMasterHasStop: TBooleanField;
    adsMasterStoper: TStringField;
    adsMasterStopTime: TDateTimeField;
    adsMasterStopMemo: TStringField;
    procedure adsMasterDeptNameChange(Sender: TField);
  private
    { Private declarations }
  protected
    procedure ModuleInit;override;
  public
    { Public declarations }
    TreeView1: TTreeView;
  end;

var
  dtmda_Department: Tdtmda_Department;

implementation

uses uGlobal, uShare, uSQL;

{$R *.dfm}

{ Tdtmda_Department }

procedure Tdtmda_Department.ModuleInit;
begin
  inherited;
  FUniqueTable := 'da_Department';
end;

procedure Tdtmda_Department.adsMasterDeptNameChange(Sender: TField);
var
  ParentText: string;
begin
  inherited;
  if FFormState=fsAdd then
  begin
    if Assigned(TreeView1.Selected) and (TreeView1.Selected.Level=0) then
      adsMaster.FieldByName('DeptFullName').AsString := '<' + Sender.AsString + '>'
    else
      adsMaster.FieldByName('DeptFullName').AsString :=
        GetParentPathName(TreeView1, TreeView1.Selected, ParentText)
          + '<' + pExTreeNode(TreeView1.Selected.Data)^.Text + '>'
          + '<' + Sender.AsString + '>'
  end
  else if FFormState=fsEdit then
    adsMaster.FieldByName('DeptFullName').AsString :=
      GetParentPathName(TreeView1, TreeView1.Selected, ParentText)
        + '<' + Sender.AsString + '>';
  if adsMaster.State in [dsInsert, dsEdit] then
  begin
    adsMaster.FieldByName('HelperCode').AsString := uSQL.GetHzPy(adsMaster.FieldByName('DeptName').AsString);
  end;
end;

end.
